﻿<UserControl x:Class="SilverlightDemoApp.View.QuestionView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:vm="clr-namespace:SilverlightDemoApp.ViewModel" 
    xmlns:Buttons="clr-namespace:SilverlightDemoApp.Buttons" 
    Width="400" Height="300">

    <UserControl.DataContext>
        <vm:QuestionViewModel />
    </UserControl.DataContext>
    
    <Grid x:Name="LayoutRoot" Background="LightBlue">
        <StackPanel Orientation="Vertical">
            <ItemsControl ItemsSource="{Binding Path=Questions}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Width="300" Height="32">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="QuestionText" HorizontalAlignment="Stretch" Text="{Binding Path=Text}" Grid.Column="0"/>
                            <TextBox x:Name="QuestionAnswered" Text="{Binding Path=ProvidedAnswer, Mode=TwoWay}" Width="20" HorizontalAlignment="Right"  Grid.Column="1"/>
                            <CheckBox x:Name="GradeCheck" IsChecked="{Binding Path=Grade}" Grid.Column="2" IsEnabled="False"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Buttons:CommandButton x:Name="GradeButton" Content="Check." VerticalAlignment="Center" Grid.Column="3"
                                    HorizontalAlignment="Center" 
                                    Command="{Binding Path=CheckGrade}" />
            <TextBlock x:Name="NumberLabel" HorizontalAlignment="Left" Text="Number:" />
            <TextBox x:Name="NumberText" HorizontalAlignment="Left" Text="{Binding Path=Number.Value, Mode=TwoWay}"/>
            <TextBlock x:Name="ChangeLogLabel" HorizontalAlignment="Left" Text="Number changelog (MVVM Foundation PropertyObserver):" />
            <ScrollViewer 
                    x:Name="_scrollViewer" 
                    x:FieldModifier="private" 
                    VerticalScrollBarVisibility="Auto"
                    >
                <ItemsControl ItemsSource="{Binding Path=ChangeLog, Mode=OneTime}" />
            </ScrollViewer>
        </StackPanel>
    </Grid>
</UserControl>